package com.zxl.always.on.display.ui.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;

import com.zxl.always.on.display.constant.ICustomAction;
import com.zxl.always.on.display.constant.LockerSetting;
import com.zxl.always.on.display.ui.helper.ScreenHelper;
import com.zxl.always.on.display.ui.receiver.ScreenReceiver;
import com.zxl.process.sdk.DaemonClient;
import com.zxl.process.sdk.NotificationAssistService;

/**
 * Created by Administrator on 2018/2/24.
 */

public class ScreenService extends Service {

    private ScreenHelper mScreenHelper;

    private ScreenReceiver mScreenReceiver;

    @Override
    public void onCreate() {
        super.onCreate();
        mScreenHelper = new ScreenHelper(this);
        mScreenReceiver = new ScreenReceiver(this, mScreenHelper);
        mScreenReceiver.registerReceiver();
        DaemonClient.getInstance().setForgroundService(this, ScreenService.InnerService1.class);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent == null) {
            return START_STICKY;
        }
        String action = intent.getAction();
        if (ICustomAction.ACTION_REFRESH_SETTINGS.equals(action)) {
            LockerSetting.init();
        } else if (ICustomAction.ACTION_CLOCK_STYLE.equals(action)) {
            mScreenHelper.refreshView();
        }
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mScreenReceiver.unregisterReceiver();
    }

    /**
     * 内部服务，用于设置前台进程
     */
    public static class InnerService1 extends NotificationAssistService {
    }

    public static void startCoreService(Context activity) {
        activity.startService(new Intent(activity, ScreenService.class));
    }
}
